// pages/flea/mySend/index.js
var app = getApp(), fetchApi = require("../../../../utils/httpPost.js"), common_Js = require("../../../../component/common.js")
import Toast from '../../../../component/vant/toast/toast';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    recordList:[],
    pageIndex:1,
    pageSize:10,
    loading: false,
    netWork: true,
    isLoading: true,
    netWork:false,
    hasData:false,
    searchValue:'',
    estate_id:0,
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log('notice',options)
    this.data.estate_id = app.getStorageSync('estate_id')
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.initRequest()
  },
  
  onSearch(val){
    console.log('onSearch',val);
    this.data.searchValue = val.detail;
    this.data.pageIndex = 1;
    this.setData({
      recordList: [],
    })
    this.onHttpInit();
  },
  onSearchClick(val){
    console.log('onSearchClick',val)
    this.data.pageIndex = 1;
    this.setData({
      recordList: [],
    })
    this.onHttpInit();
  },
  initRequest(){
    var that = this;
    that.data.pageIndex = 1;
    that.setData({
      loading: false,
      netWork: false,
      isLoading: true,
      hasData:false,
      recordList:[]
    });
    that.onHttpInit()
  },
  /**
   * 获取页面数据的 http请求
   */
  onHttpInit: function () {
    var that = this;
    fetchApi.httpPost('/estate/visit/record', {
      estate_id: that.data.estate_id,
      pageSize: that.data.pageSize,
      pageIndex: that.data.pageIndex,
      keyword: that.data.searchValue,
    }, function (res) {
      if (res.data.code == 0) {
        if (res.data.totalcount > 0) {
          that.data.pageIndex += 1;
          console.log("访客登记记录列表", res)
          var records = res.data.data.recordList;
          if(records.length > 0){
            for (var index in records) {
              that.data.recordList.splice(that.data.recordList.length, 0, records[index]);
            }
            that.setData({
              hasData: true,
              recordList: that.data.recordList
            })
          }
        }
      }
      that.setData({
         isLoading: false, loading: true, netWork: true,
      })
    }, function (res) {
        that.setData({ hasData: false,  isLoading: false,  loading: true, netWork: true })
    })
    wx.hideNavigationBarLoading() //完成停止加载
    wx.stopPullDownRefresh() //停止下拉刷新
  },
  
  /**
   * 页面相关事件处理函数--监听用户下拉动作  下拉刷新
   */
  onPullDownRefresh: function () {
    this.initRequest()
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.onHttpInit()
  },
})